<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" version="-//W3C//DTD XHTML 1.1//EN" dir="ltr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>HelloEvtService Example</title>
    <link href="css/samples.css" rel="stylesheet" type="text/css">
    <?php
        require_once("lib/jsonsscli.php");
        ini_set("error_reporting", false);
    ?>
</head>
<body><div id="page-content">

    <h1>HelloEvtService Example</h1>

    <h3>Service exchange log</h3>
    <pre class="console"><?php 

    JSONSSProxy::initLibrary();

    $url = "http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . "/helloevt.php";
    echo "URL = " . $url . "\r\n";

    function onHello($d) {
        echo "Event Hello caught by function\r\n";
        echo "attached data is: " . $d . "\r\n";
    }

    class Catcher {
        public function onHello($d) {
            echo "Event Hello caught by class method\r\n";
            echo "attached data is: " . $d . "\r\n";
        }
    }

    $catcher = new Catcher();

    try { 
        $proxy = JSONSSProxy::fromUrl($url);
        echo "Got proxy object: HelloEvtService.serviceUrl = " . $proxy->HelloEvtService->serviceUrl . "\r\n";
        echo "HelloEvtService.onHello is not set\r\n";
        echo "HelloEvtService.SayHello() returns: " . $proxy->HelloEvtService->SayHello() . "\r\n";
        $proxy->HelloEvtService->onHello = "onHello";
        echo "HelloEvtService.onHello is set to function onHello()\r\n";
        echo "HelloEvtService.SayHello() returns: " . $proxy->HelloEvtService->SayHello() . "\r\n";
        $proxy->HelloEvtService->onHello = array($catcher, "onHello");
        echo "HelloEvtService.onHello is set to class method Catcher.onHello()\r\n";
        echo "HelloEvtService.SayHello() returns: " . $proxy->HelloEvtService->SayHello() . "\r\n";
        $proxy->HelloEvtService->onHello = NULL;
        echo "HelloEvtService.onHello is set to NULL\r\n";
        echo "HelloEvtService.SayHello() returns: " . $proxy->HelloEvtService->SayHello() . "\r\n";
        echo "HelloEvtService.Version is: " . $proxy->HelloEvtService->Version . "\r\n";
    } catch (Exception $x) { 
        echo "Ooops! Exception: ". $x->getMessage() . "\r\n"; 
    } 

    try { 
        echo "Trying to set read-only property HelloEvtService.Version\r\n";
        $proxy->HelloEvtService->Version = "2.0";
        echo "Ooops! Succeed...\r\n"; 
    } catch (Exception $x) { 
        echo "Fine. Exception: ". $x->getMessage() . "\r\n"; 
    } 
 
    JSONSSProxy::shutdownLibrary();

    ?></pre>
</div></body>
</html>
